/*用户列表*/
layui.use('table', function(){
    var table = layui.table;
    table.render({
        id:"roleForm",
        elem: '#roleForm',
        url:'getRoleData.html',
        method: 'POST', //方式
        page:{
            //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
            //,curr: 5 //设定初始在第 5 页
            groups: 1, //只显示 1 个连续页码
            first: false, //不显示首页
            last: false //不显示尾页
        },
        cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        cols: [ [
            {type:'checkbox'},
            {field:'roleName', title: '角色名称'},
            {field:'roleSign', title: '角色编码', sort: true},
            {field:'status', title: '状态', sort: true,templet: '#statusTpl'},
            {field:'remark',   title: '备注', sort: true}
        ] ]
    });
});
function search(){

    var roleName = $("input[name='roleName']").val();
    var roleSign = $("input[name='roleSign']").val();

    var table = layui.table;
    //table.reload("orgForm");
    table.reload("roleForm", { //此处是上文提到的 初始化标识id
        where: {
            //key: { //该写法上文已经提到
            roleName: roleName,roleSign:roleSign
            //}
        }
    });
}

function add() {
    parent.layer.open({
        type: 2,
        title: '角色管理-新增',
        //title: false, //不显示标题
        shadeClose: true,
        skin: 'layui-layer-molv',
        shade: 0.8,
        area: ['35%', '77%'],
        content: ['sys/role/add.html','no'], //iframe的url
        end:function () {
            reloadTable("roleForm");
        }
    });
}
function edit(){
    var table = layui.table;
    var rows = table.checkStatus('roleForm'); //test即为基础参数id对应的值
    var id = rows.data[0].roleId;
    if(rows.data.length!=1){
        layer.msg('请选择一条数据');
        return false;
    }else {
        var url = 'sys/role/edit.html?roleId='+id;
        parent.layer.open({
            type: 2,
            title: '用户管理-编辑',
            shadeClose: true,
            skin: 'layui-layer-molv',
            shade: 0.8,
            area: ['35%', '77%'],
            content: [url,'no'], //iframe的url
            end:function () {
                reloadTable("roleForm");
            }
        });
    }
}
function del(){
    var table = layui.table;
    var rows = table.checkStatus('roleForm'); //test即为基础参数id对应的值
    var ids=[];
    if(rows.data.length<1){
        layer.msg('请选择一条数据');
        return false;
    }
    //询问框

    layer.confirm('确定要删除？', {
        btn: ['确定','取消'], //按钮
        icon: 3, title:'删除用户'
    }, function(){
        for(var i=0;i<rows.data.length;i++){

            var rowid = rows.data[i].roleId;
            ids.push(rowid);
        }
        $.ajax({
            type: "POST",
            url:"delete.html",
            data:{'ids':ids},
            traditional:true,
            cache: false,
            success:function (data) {
                if(data.code == 0){
                    layer.msg('删除成功',{time:1500},
                        function () {
                            reloadTable("roleForm");
                        })
                }
                if("fail"==data){
                    layer.msg("删除失败",{icon:1,time:1500
                    })
                }
            }
        })
    });
}
function configure() {
    var table = layui.table;
    var rows = table.checkStatus('roleForm');
    if(rows.data.length!=1){
        layer.msg('请选择一个角色');
        return false;
    }else{
        var id = rows.data[0].roleId;
    }
    var url = 'sys/role/configure.html?roleId='+id;
    parent.layer.open({
        title:'分配权限',
        type: 2,
        area: ['20%', '77%'],
        skin: 'layui-layer-rim', //加上边框
        content: [url,'no'], //iframe的url
        end:function () {
            reloadTable("roleForm");
        }
    });
}